home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / ppp / ppp-in.frm.z / ppp-in.frm
Encoding:
Text File  |  2002-06-12  |  12.4 KB  |  402 lines

  1. #!/usr/bin/perl5
  2. #
  3. # ppp-in.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: ppp-in.frm,v 1.36 1997/11/17 19:09:46 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $conf = "/etc/passwd";
  26. $dummy = "/etc/passwd.temp";
  27. $myname = "ppp-in.cgi";
  28. $help_page = "ppp-in-help.html";
  29. $title = "Dial-in PPP Accounts";
  30.  
  31. $js_main =
  32. "which = \"none\";
  33. $js_help
  34. function runSubmit() {
  35.     // onClick gets processed before onSubmit
  36.     if(which == \"add\") return runAdd();
  37.     if(which == \"edit\") return runEdit();
  38.     if(which == \"delete\") return runDelete();
  39.     return (true);
  40. }    
  41. function markAdd() { which = \"add\"; }
  42. function markEdit() { which = \"edit\"; }
  43. function markDelete() { which = \"delete\"; }
  44. function markOther() { which = \"none\"; }
  45. function runAdd()  {
  46.     form = document.PPPForm;
  47.     if (!testLogin(form)) return (false);
  48.     return (true);
  49. }
  50. function runEdit()  {
  51.     Ctrl = document.PPPForm.chosen;
  52.     none = true;
  53.     for(i = 0; i < Ctrl.length; i++) { if (Ctrl.options[i].selected) { none = false; break; } }
  54.     if(none) { errorBox (Ctrl, \"To edit an existing account, first select an account \\nfrom the list, then click the edit button.\"); return (false); }
  55.     return (true);
  56. }
  57. function runDelete()  {
  58.     Ctrl = document.PPPForm.chosen;
  59.     none = true;
  60.     for(j = 0; j < Ctrl.length; j++) { if (Ctrl.options[j].selected) { none = false; break; } }
  61.     if(none) { errorBox (Ctrl, \"To delete an existing account, first select an account \\nfrom the list, then click the delete button.\"); return (false); }
  62.     return (true);
  63. }
  64. function testLogin(form) {
  65.     Ctrl = form.new_account;
  66.     if (Ctrl.value == \"\") { errorBox (Ctrl, \"The login name is required.\"); return (false); } 
  67.     error = testLoginChars(Ctrl.value); 
  68.     if (error == 1) { errorBox (Ctrl, \"The login name cannot be more \\nthan 8 characters long.\"); return (false); }
  69.     if (error == 2) { errorBox (Ctrl, \"The login name cannot contain the \" + illegal + \" character.\"); return (false); }
  70.     if (error == 3) { errorBox (Ctrl, \"The login name cannot contain spaces.\"); return (false); }
  71.     return (true);
  72. }
  73. function testLoginChars(word) {
  74.     if (word.length > 8) return 1;
  75.     loginChars = \"_-\.{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  76.     for(j = 0; j < loginChars.length; j++) {
  77.         c = loginChars.charAt(j);
  78.         if (word.indexOf(c, 0) != -1) { illegal = c; return 2; }
  79.     }
  80.     for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 3; }
  81.     return 0;
  82. }
  83. function errorBox (Ctrl, ErrorMessage) {
  84.     alert (ErrorMessage);  Ctrl.focus();  return;
  85. }";
  86.  
  87. $js_add =
  88. "which = \"none\";
  89. $js_help
  90. function runSubmit() {
  91.     // onClick must get processed before onSubmit
  92.     if(which == \"ok\") return runOK();
  93.     return (true);
  94. }   
  95. function markOK() { which = \"ok\"; }
  96. function markOther() { which = \"none\"; }
  97. function runOK()  {
  98.     form = document.AddForm;
  99.     // JavaScript can't look at password fields.
  100.     return (true);
  101. }
  102. function errorBox (Ctrl, ErrorMessage) {
  103.     alert (ErrorMessage);  Ctrl.focus();  return;
  104. }";
  105.  
  106. $js_edit = 
  107. "which = \"none\";
  108. $js_help
  109. function runSubmit() {
  110.     // onClick gets processed before onSubmit
  111.     if(which == \"ok\") return runOK();
  112.     return (true);
  113. }    
  114. function markOK() { which = \"ok\"; }
  115. function markOther() { which = \"none\"; }
  116. function runOK()  {
  117.     form = document.EditForm;
  118.     if (!testLogin(form)) return (false);
  119.     // JavaScript can't look at password fields.
  120.     return (true);
  121. }
  122. function testLogin(form) {
  123.     Ctrl = form.login;
  124.     if (Ctrl.value == \"\") { errorBox (Ctrl, \"The login name is required.\"); return (false); } 
  125.     error = testLoginChars(Ctrl.value); 
  126.     if (error == 1) { errorBox (Ctrl, \"The login name cannot be more \\nthan 8 characters long.\"); return (false); }
  127.     if (error == 2) { errorBox (Ctrl, \"The login name cannot contain the \" + illegal + \" character.\"); return (false); }
  128.     if (error == 3) { errorBox (Ctrl, \"The login name cannot contain spaces.\"); return (false); }
  129.     return (true);
  130. }
  131. function testLoginChars(word) {
  132.     if (word.length > 8) return 1;
  133.     loginChars = \"_-\.{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  134.     for(j = 0; j < loginChars.length; j++) {
  135.         c = loginChars.charAt(j);
  136.         if (word.indexOf(c, 0) != -1) { illegal = c; return 2; }
  137.     }
  138.     for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 3; }
  139.     return 0;
  140. }
  141. function errorBox (Ctrl, ErrorMessage) {
  142.     alert (ErrorMessage);  Ctrl.focus();  return;
  143. }";
  144.  
  145.  
  146. print "Content-type: text/html\n\n";
  147.  
  148. if ( ! -e "/usr/etc/ppp" ) {
  149.     &title_block($title);
  150.     &header_block($title);
  151.     print "<i>PPP software not installed.  Install subsystem 
  152.         </i><b>eoe.sw.ppp</b><i> from the distribution CD.</i>";
  153.     exit 0;
  154. }
  155.  
  156. &get_fields;
  157.  
  158. &getAccounts;
  159.  
  160. if (%fld) {
  161.     $fld{'chosen'} =~ /([\w.-]+)/;
  162.     $fld{'chosen'} = $1;
  163.  
  164.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  165.     $help =~ s/cgi$/hlp/;
  166.     exec $help if ($fld{'help'} eq "Help");
  167.  
  168.     if ($fld{'add'}) {
  169.         &error(2,"Login name required.") if !$fld{'new_account'};
  170.         @test = getpwnam($fld{'new_account'});
  171.         &error(2,"Account already exists.") if $test[0];
  172.         &error(2,"Invalid login name.") 
  173.         if $fld{'new_account'} =~ /$METACHARS/o || $fld{'new_account'} =~ /\s/; 
  174.         $val{'login'} = $fld{'new_account'}; 
  175.         &addAccount; 
  176.     }
  177.     elsif ($fld{'delete'}) {
  178.         &error(2,"To delete an existing account, first select an account from
  179.             list, then click the delete button.") if !$fld{'chosen'};
  180.         $message = qq|Click "Ok" to save changes.|;
  181.         &generic($fld{'chosen'}); 
  182.     }
  183.     elsif ($fld{'edit'}) {
  184.         &error(2,"To edit an existing account, first select an account from
  185.             list, then click the edit button.") if !$fld{'chosen'};
  186.         $val{'login'} = $fld{'chosen'}; 
  187.         &editAccount; 
  188.     }
  189.     elsif ($fld{'doedit'}) { &formValid_doEdit; &doEdit; &getAccounts; &generic; }
  190.     elsif ($fld{'doit'}) { &tryToDelete; &getAccounts; &generic; }
  191.     elsif ($fld{'doadd'}) { &formValid_doAdd; &doAdd; &getAccounts; &generic; }
  192.     else { $message = "Use buttons to submit form."; $val{'new_account'} = $fld{'new_account'}; &generic; }
  193. } else { &generic; }
  194.  
  195. sub formValid_doAdd {
  196.     if (!$fld{'password'}) 
  197.     { &error(0,"You must enter a password."); }
  198.     if ($fld{'password'} ne $fld{'passcheck'}) 
  199.     { &error(0,"Input passwords not equivalent."); }
  200.     &error(0,"Invalid login name.") if $fld{'login'} =~ /$METACHARS/o;
  201. }
  202.  
  203. sub formValid_doEdit {
  204.     if ($fld{'password'} ne $fld{'passcheck'}) 
  205.     { &error(1,"Input passwords not equivalent."); }
  206.     &error(1,"Invalid login name.") if $fld{'login'} =~ /$METACHARS/o;
  207. }
  208.  
  209. sub error {
  210.     &error_block($_[1]);
  211.     %val = %fld;
  212.     if ($_[0] == 0) { &addAccount; }
  213.     elsif ($_[0] == 1) { &editAccount; }
  214.     else { &generic; }
  215.     exit 0;
  216. }
  217.  
  218. sub doEdit {
  219.    open(IN,"< $conf");
  220.     open(OUT,"> $dummy");
  221.     while(<IN>) {
  222.     @items = split(/:/);
  223.     if ($items[0] ne $fld{'chosen'}) { print OUT $_; }
  224.     else { $oldcrypt = $items[1]; }
  225.     }
  226.     close(IN);
  227.     close(OUT);
  228.     rename($dummy,$conf);
  229.  
  230.     if ($fld{'password'}) {
  231.     &add_password($fld{'login'},$fld{'password'},0,0,$fld{'login'}." ppp","/","/usr/etc/ppp");
  232.     } else {
  233.     open(OUT,">> $conf");
  234.     print OUT "$fld{'login'}:$oldcrypt:0:0:$fld{'login'} ppp:/:/usr/etc/ppp\n";
  235.     close(OUT);
  236.     }
  237.     
  238.     $message = "Account edited.";
  239. }    
  240.  
  241. sub editAccount {
  242.     &js_title_block($title,$js_edit);
  243.     &header_block("Edit Dial-in PPP Account");
  244.  
  245.     print "<form name=EditForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  246.  
  247.     print qq|<input type=hidden name="chosen" value=$fld{'chosen'}>|;
  248.  
  249.     print "<center><table cellpadding=5 width=450>";
  250.  
  251.     print "<tr><th align=left>Login name:</th><th align=left>",
  252.       &text('login',$val{'login'}, 20),"</th></tr>";
  253.  
  254.     print "<tr><th align=left>Password:</th><th align=left>";
  255.     print qq|<input type=password name="password" size=20>|;
  256.     print "</th></tr>";
  257.     print "<tr><th align=left>(Password again):</th><th align=left>";
  258.     print qq|<input type=password name="passcheck" size=20>|;
  259.     print "</th></tr>";
  260.  
  261.     print "</table></center>";
  262.  
  263.     print &js_buttons('doedit','Ok','onClick="markOK()"',
  264.         'onClick="markOther()"',
  265.         "onClick=\"do_help('$help_page'); return (false)\"");
  266.  
  267.     print "</form></body></html>";
  268. }
  269.     
  270. sub tryToDelete {
  271.     $account = $fld{'del_name'};
  272.     if ($account eq "") { return; }
  273.  
  274.     open(IN,"< $conf");
  275.     open(OUT,"> $dummy");
  276.     while(<IN>) {
  277.     $line = $_;
  278.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  279.     @items = split(/:/,$line);
  280.     chop $items[6];
  281.     if ($items[6] eq "/usr/etc/ppp" && $items[0] eq $account) {
  282.         next;
  283.     } else { print OUT $line; }
  284.     }
  285.     close(IN);
  286.     close(OUT);
  287.     rename($dummy,$conf);
  288.  
  289.     $message = "Account deleted.";    
  290. }
  291.  
  292. sub doAdd {
  293.     &add_password($fld{'login'},$fld{'password'},0,0,$fld{'login'}." ppp",
  294.         "/","/usr/etc/ppp");
  295.     $message = "New account added.";
  296. }
  297.  
  298. sub addAccount {
  299.     &js_title_block($title,$js_add);
  300.     &header_block("Add New Dial-in PPP Account");
  301.  
  302.     print "<form name=AddForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  303.  
  304.     print "<center><table>";
  305.  
  306.     print "<input type=hidden name=login value=$val{'login'}>";
  307.  
  308.     print "<tr><th align=left>Login name:</th><td><tt>",
  309.       $val{'login'},"</tt></td></tr>";
  310.  
  311.     print "<tr><th align=left>Password:</th><th align=left>";
  312.     print qq|<input type=password name="password" size=20>|;
  313.     print "</th></tr>";
  314.  
  315.     print "<tr><th align=left>(Password again):</th><th align=left>";
  316.     print qq|<input type=password name="passcheck" size=20>|;
  317.     print "</th></tr>";
  318.  
  319.     print "</table></center><br>";
  320.  
  321.     print &js_buttons('doadd','Ok','onClick="markOK()"','onClick="markOther()"',
  322.         "onClick=\"do_help('$help_page'); return (false)\"");
  323.  
  324.     print "</form></body></html>";
  325. }
  326.  
  327. sub getAccounts {
  328.     $i = 0;
  329.     open(IN,"< $conf");
  330.     while(<IN>) {
  331.     $line = $_;
  332.     if ($line =~ /^\s*\#/) { next; }
  333.     @items = split(/:/,$line);
  334.     chop $items[6];
  335.     if ($items[6] eq "/usr/etc/ppp") {
  336.         $name[$i] = $items[0];
  337.         $i++;
  338.     }
  339.     }
  340.     $number = $i;
  341.     close(IN);
  342. }
  343.  
  344. sub generic {
  345.     &js_title_block($title,$js_main);
  346.     &header_block($title);
  347.  
  348.     if (!$number && !$message) { $message = "No existing dial-in PPP accounts."; }
  349.     print "<i>$message</i>";
  350.  
  351.     print "<form name=PPPForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  352.     
  353.     if ($_[0]) { print qq|<input type=hidden name="del_name" value=$_[0]>|; }
  354.  
  355.     if ($number) {
  356.     print "<h3>Account name:</h3><center>";
  357.  
  358.     print "<table width=400>";
  359.  
  360.     print qq|<tr><td><input type=submit name="add" value="Add New Account"
  361. onClick="markAdd()">
  362.         </td><td><input name="new_account" value="$val{'new_account'}" size=19></td></tr>|;
  363.  
  364.     print "<tr><td>";
  365.     print qq|<input type=submit name="edit" 
  366.         value="Edit Selected Account" onClick="markEdit()"></td>|;
  367.  
  368.     undef @locList;
  369.     for ($i=0;$i<$number;$i++) { 
  370.         if ($_[0] ne $name[$i]) { push(@locList,$name[$i]); }
  371.     }
  372.  
  373.     print "<td rowspan=2>";
  374.  
  375.     print &choice_list(*locList,"chosen",20);
  376.  
  377.     print "</td></tr>";
  378.  
  379.     print qq|<tr><td><input type=submit name="delete" 
  380.         value="Delete Selected Account" onClick="markDelete()"></td></tr>|;    
  381.  
  382.  
  383.     print "</table></center><br>";
  384.     } else {
  385.     print "<center><table width=400>";
  386.  
  387.     print qq|<tr><td><input type=submit name="add" value="Add New Account"
  388. onClick="markAdd()">
  389.         </td><td><input name="new_account" value="$val{'new_account'}" size=19></td></tr>|;
  390.  
  391.     print "<tr><td>";
  392.     print "</table>";
  393.     }
  394.  
  395.     print &js_buttons('doit','Ok','onClick="markOther()"',
  396.         'onClick="markOther()"',
  397.         "onClick=\"do_help('$help_page'); return (false)\"");
  398.  
  399.     print "</form></body></html>";
  400. }
  401.  
  402.